package com.ruoyi.serviceItem.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.serviceItem.service.OrderService;
import com.ruoyi.serviceItem.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderServiceImpl orderService;

    @GetMapping("/list")
    public R listOrder(@RequestParam Long storeId,
                       @RequestParam(required = false) Integer orderStatus,
                       @RequestParam(required = false) String searchKey) {
        return R.ok(orderService.listOrder(storeId, orderStatus, searchKey));
    }

    @GetMapping("/detail")
    public R getDetail(Long orderId) {
        return R.ok(orderService.getDetail(orderId));
    }

    @PostMapping("/verify")
    public R<String> verifyOrder(@RequestBody Map<String, Long> param) {
        try {
            Date verificationTime = orderService.verifyOrder(param.get("orderId"));
            return R.ok(verificationTime.toString());
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }



}
